﻿using Pay.Core;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Pay.Token.Controllers
{
    [AppAuthorize("Member")]
    public class FollowPubAccountController : GeneralController
    {
        private ISoupTaskService _iSoupTaskService;

        public FollowPubAccountController(ISoupTaskService iSoupTaskService)
        {
            _iSoupTaskService = iSoupTaskService;
        }

        // GET: FollowPubAccount
        public ActionResult Index()
        {
            var model = _iSoupTaskService.GetSoupTaskByType(ETaskType.FollowPubAccount);
            var task = _iSoupTaskService.AppGetSoupTask(model.id, UserId);

            ViewData["task"] = task;
            return View();
        }
        /// <summary>
        /// 领取关注公众号马力值
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> TaskCode(string code)
        {
            var result =  await _iSoupTaskService.TaskRecive(UserId, ETaskType.FollowPubAccount, 0, code);
            if (result) {
                return Json(ResultToJson.Json("领取成功", true), JsonRequestBehavior.AllowGet);
            } else {
                return Json(ResultToJson.Json("领取失败", false), JsonRequestBehavior.AllowGet);
            }
        }
    }
}